package cz.data.domain.metadata.controller;

import cz.data.common.base.BaseController;
import cz.data.common.base.BaseResponse;
import cz.data.common.base.SimpleDataResponse;
import cz.data.domain.metadata.model.dto.MetadataAuthorizeDto;
import cz.data.domain.metadata.service.MetadataAuthorizeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"元数据授权"})
@RestController
@RequestMapping("/authorizes")
public class MetadataAuthorizeController extends BaseController {

    @Autowired
    private MetadataAuthorizeService metadataAuthorizeService;

    @GetMapping("/getAuthorizedMetadata/{id}")
    public SimpleDataResponse<List<String>> getAuthorizedMetadata(@PathVariable String id) {
        List<String> list = metadataAuthorizeService.getAuthorizedMetadata(id);
        return new SimpleDataResponse<>(list);
    }

    @PostMapping("/metadata")
    public BaseResponse metadataAuthorize(@RequestBody @Validated MetadataAuthorizeDto metadataAuthorizeDto) {
        metadataAuthorizeService.metadataAuthorize(metadataAuthorizeDto);
        return BaseResponse.success();
    }

    @GetMapping("/refresh")
    public BaseResponse refreshCache() {
        metadataAuthorizeService.refreshCache();
        return BaseResponse.success();
    }
}
